package com.tencent.bugly.crashreport.common.info;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.os.Process;
import com.tencent.bugly.proguard.an;
import com.tencent.bugly.proguard.aq;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/* compiled from: BUGLY */
/* loaded from: classes.dex */
public class a {
    private static a an;
    public boolean F;
    public SharedPreferences N;
    private final Context O;
    private String P;
    private String Q;
    public final String b;
    public String d;
    public final String e;
    public String f;
    public String g;
    public final String l;
    public final String m;
    public final String n;
    public String q;
    public boolean h = true;
    public final String i = "com.tencent.bugly";
    public final String j = "3.0.0";
    public final String k = "";
    private String R = "unknown";
    private String S = "unknown";
    private String T = "";
    public long o = 0;
    private String U = null;
    private String V = null;
    private String W = null;
    private String X = null;
    private long Y = -1;
    private long Z = -1;
    private long aa = -1;
    private String ab = null;
    private String ac = null;
    private Map<String, PlugInBean> ad = null;
    private boolean ae = true;
    private String af = null;
    public String p = null;
    private String ag = null;
    public String r = null;
    private Boolean ah = null;
    private String ai = null;
    private String aj = null;
    private String ak = null;
    public String s = null;
    public String t = null;
    private Map<String, PlugInBean> al = null;
    private Map<String, PlugInBean> am = null;
    public List<String> u = null;
    private int ao = -1;
    private int ap = -1;
    private Map<String, String> aq = new HashMap();
    private Map<String, String> ar = new HashMap();
    private Map<String, String> as = new HashMap();
    private boolean at = true;
    public String v = "unknown";
    public long w = 0;
    public long x = 0;
    public long y = 0;
    public long z = 0;
    public boolean A = false;
    public String B = null;
    public String C = null;
    public String D = null;
    public boolean E = false;
    public Boolean G = null;
    public Boolean H = null;
    public HashMap<String, String> I = new HashMap<>();
    private String au = null;
    private String av = null;
    private String aw = null;
    private String ax = null;
    private String ay = null;
    public boolean J = true;
    public List<String> K = new ArrayList();
    public boolean L = false;
    public com.tencent.bugly.crashreport.a M = null;
    private final Object az = new Object();
    private final Object aA = new Object();
    private final Object aB = new Object();
    private final Object aC = new Object();
    private final Object aD = new Object();
    private final Object aE = new Object();
    private final Object aF = new Object();
    public final long a = System.currentTimeMillis();
    public final byte c = 1;

    public String c() {
        return "3.0.0";
    }

    private a(Context context) {
        this.q = null;
        this.F = false;
        this.O = aq.a(context);
        b(context);
        this.d = AppInfo.a(context);
        this.e = AppInfo.a(context, Process.myPid());
        this.l = b.m();
        this.m = b.a();
        this.q = AppInfo.c(context);
        this.n = "Android " + b.b() + ",level " + b.c();
        StringBuilder sb = new StringBuilder();
        sb.append(this.m);
        sb.append(";");
        sb.append(this.n);
        this.b = sb.toString();
        c(context);
        try {
            if (!context.getDatabasePath("bugly_db_").exists()) {
                this.F = true;
                an.c("App is first time to be installed on the device.", new Object[0]);
            }
        } catch (Throwable th) {
            if (com.tencent.bugly.b.c) {
                th.printStackTrace();
            }
        }
        this.N = aq.a("BUGLY_COMMON_VALUES", context);
        an.c("com info create end", new Object[0]);
    }

    private void b(Context context) {
        PackageInfo b = AppInfo.b(context);
        if (b == null) {
            return;
        }
        try {
            this.p = b.versionName;
            this.B = this.p;
            this.C = Integer.toString(b.versionCode);
        } catch (Throwable th) {
            if (an.a(th)) {
                return;
            }
            th.printStackTrace();
        }
    }

    private void c(Context context) {
        Map<String, String> d = AppInfo.d(context);
        if (d == null) {
            return;
        }
        try {
            this.u = AppInfo.a(d);
            String str = d.get("BUGLY_APPID");
            if (str != null) {
                this.ag = str;
                c("APP_ID", this.ag);
            }
            String str2 = d.get("BUGLY_APP_VERSION");
            if (str2 != null) {
                this.p = str2;
            }
            String str3 = d.get("BUGLY_APP_CHANNEL");
            if (str3 != null) {
                this.r = str3;
            }
            String str4 = d.get("BUGLY_ENABLE_DEBUG");
            if (str4 != null) {
                this.A = str4.equalsIgnoreCase("true");
            }
            String str5 = d.get("com.tencent.rdm.uuid");
            if (str5 != null) {
                this.D = str5;
            }
        } catch (Throwable th) {
            if (an.a(th)) {
                return;
            }
            th.printStackTrace();
        }
    }

    public boolean a() {
        return this.at;
    }

    public void a(boolean z) {
        this.at = z;
        com.tencent.bugly.crashreport.a aVar = this.M;
        if (aVar != null) {
            aVar.setNativeIsAppForeground(z);
        }
    }

    public static synchronized a a(Context context) {
        a aVar;
        synchronized (a.class) {
            if (an == null) {
                an = new a(context);
            }
            aVar = an;
        }
        return aVar;
    }

    public static synchronized a b() {
        a aVar;
        synchronized (a.class) {
            aVar = an;
        }
        return aVar;
    }

    public void d() {
        synchronized (this.az) {
            this.P = UUID.randomUUID().toString();
        }
    }

    public String e() {
        String str;
        synchronized (this.az) {
            if (this.P == null) {
                d();
            }
            str = this.P;
        }
        return str;
    }

    public String f() {
        if (!aq.a(this.f)) {
            return this.f;
        }
        return this.ag;
    }

    public void a(String str) {
        this.ag = str;
        c("APP_ID", str);
    }

    public String g() {
        String str;
        synchronized (this.aE) {
            str = this.R;
        }
        return str;
    }

    public void b(String str) {
        synchronized (this.aE) {
            if (str == null) {
                str = "10000";
            }
            this.R = "" + str;
        }
    }

    public void b(boolean z) {
        this.ae = z;
    }

    public String h() {
        String str = this.Q;
        if (str != null) {
            return str;
        }
        this.Q = k() + "|" + m() + "|" + n();
        return this.Q;
    }

    public void c(String str) {
        this.Q = str;
        synchronized (this.aF) {
            this.ar.put("E8", str);
        }
    }

    public synchronized String i() {
        return this.S;
    }

    public synchronized void d(String str) {
        this.S = "" + str;
    }

    public synchronized String j() {
        return this.T;
    }

    public synchronized void e(String str) {
        this.T = "" + str;
    }

    public String k() {
        if (this.ae) {
            if (this.U == null) {
                this.U = b.a(this.O);
            }
            return this.U;
        }
        return "";
    }

    public String l() {
        if (this.ae) {
            String str = this.V;
            if (str == null || !str.contains(":")) {
                this.V = b.d(this.O);
            }
            return this.V;
        }
        return "";
    }

    public String m() {
        if (this.ae) {
            if (this.W == null) {
                this.W = b.b(this.O);
            }
            return this.W;
        }
        return "";
    }

    public String n() {
        if (this.ae) {
            if (this.X == null) {
                this.X = b.c(this.O);
            }
            return this.X;
        }
        return "";
    }

    public long o() {
        if (this.Y <= 0) {
            this.Y = b.f();
        }
        return this.Y;
    }

    public long p() {
        if (this.Z <= 0) {
            this.Z = b.h();
        }
        return this.Z;
    }

    public long q() {
        if (this.aa <= 0) {
            this.aa = b.j();
        }
        return this.aa;
    }

    public String r() {
        if (this.ab == null) {
            this.ab = b.a(this.O, true);
        }
        return this.ab;
    }

    public String s() {
        if (this.ac == null) {
            this.ac = b.h(this.O);
        }
        return this.ac;
    }

    public void a(String str, String str2) {
        if (str == null || str2 == null) {
            return;
        }
        synchronized (this.aA) {
            this.I.put(str, str2);
        }
    }

    public String t() {
        try {
            Map<String, ?> all = this.O.getSharedPreferences("BuglySdkInfos", 0).getAll();
            if (!all.isEmpty()) {
                synchronized (this.aA) {
                    for (Map.Entry<String, ?> entry : all.entrySet()) {
                        this.I.put(entry.getKey(), entry.getValue().toString());
                    }
                }
            }
        } catch (Throwable th) {
            an.a(th);
        }
        if (this.I.isEmpty()) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry2 : this.I.entrySet()) {
            sb.append("[");
            sb.append(entry2.getKey());
            sb.append(",");
            sb.append(entry2.getValue());
            sb.append("] ");
        }
        c("SDK_INFO", sb.toString());
        return sb.toString();
    }

    public String u() {
        if (this.ay == null) {
            this.ay = AppInfo.e(this.O);
        }
        return this.ay;
    }

    public synchronized Map<String, PlugInBean> v() {
        if (this.ad != null && this.ad.size() > 0) {
            HashMap hashMap = new HashMap(this.ad.size());
            hashMap.putAll(this.ad);
            return hashMap;
        }
        return null;
    }

    public String w() {
        if (this.af == null) {
            this.af = b.l();
        }
        return this.af;
    }

    public Boolean x() {
        if (this.ah == null) {
            this.ah = Boolean.valueOf(b.n());
        }
        return this.ah;
    }

    public String y() {
        if (this.ai == null) {
            this.ai = "" + b.g(this.O);
            an.a("ROM ID: %s", this.ai);
        }
        return this.ai;
    }

    public String z() {
        if (this.aj == null) {
            this.aj = "" + b.e(this.O);
            an.a("SIM serial number: %s", this.aj);
        }
        return this.aj;
    }

    public String A() {
        if (this.ak == null) {
            this.ak = "" + b.d();
            an.a("Hardware serial number: %s", this.ak);
        }
        return this.ak;
    }

    public Map<String, String> B() {
        synchronized (this.aB) {
            if (this.aq.size() <= 0) {
                return null;
            }
            return new HashMap(this.aq);
        }
    }

    public String f(String str) {
        String remove;
        if (aq.a(str)) {
            an.d("key should not be empty %s", "" + str);
            return null;
        }
        synchronized (this.aB) {
            remove = this.aq.remove(str);
        }
        return remove;
    }

    public void C() {
        synchronized (this.aB) {
            this.aq.clear();
        }
    }

    public String g(String str) {
        String str2;
        if (aq.a(str)) {
            an.d("key should not be empty %s", "" + str);
            return null;
        }
        synchronized (this.aB) {
            str2 = this.aq.get(str);
        }
        return str2;
    }

    public void b(String str, String str2) {
        if (aq.a(str) || aq.a(str2)) {
            an.d("key&value should not be empty %s %s", "" + str, "" + str2);
            return;
        }
        synchronized (this.aB) {
            this.aq.put(str, str2);
        }
    }

    public int D() {
        int size;
        synchronized (this.aB) {
            size = this.aq.size();
        }
        return size;
    }

    public Set<String> E() {
        Set<String> keySet;
        synchronized (this.aB) {
            keySet = this.aq.keySet();
        }
        return keySet;
    }

    public Map<String, String> F() {
        synchronized (this.aF) {
            if (this.ar.size() <= 0) {
                return null;
            }
            return new HashMap(this.ar);
        }
    }

    public void c(String str, String str2) {
        if (aq.a(str) || aq.a(str2)) {
            an.d("server key&value should not be empty %s %s", "" + str, "" + str2);
            return;
        }
        synchronized (this.aC) {
            this.as.put(str, str2);
        }
    }

    public Map<String, String> G() {
        synchronized (this.aC) {
            if (this.as.size() <= 0) {
                return null;
            }
            return new HashMap(this.as);
        }
    }

    public void a(int i) {
        synchronized (this.aD) {
            int i2 = this.ao;
            if (i2 != i) {
                this.ao = i;
                an.a("user scene tag %d changed to tag %d", Integer.valueOf(i2), Integer.valueOf(this.ao));
            }
        }
    }

    public int H() {
        int i;
        synchronized (this.aD) {
            i = this.ao;
        }
        return i;
    }

    public void b(int i) {
        int i2 = this.ap;
        if (i2 != i) {
            this.ap = i;
            an.a("server scene tag %d changed to tag %d", Integer.valueOf(i2), Integer.valueOf(this.ap));
        }
    }

    public int I() {
        return this.ap;
    }

    public synchronized Map<String, PlugInBean> J() {
        Map<String, PlugInBean> map;
        map = this.al;
        if (this.am != null) {
            map.putAll(this.am);
        }
        return map;
    }

    public int K() {
        return b.c();
    }

    public String L() {
        if (this.au == null) {
            this.au = b.o();
        }
        return this.au;
    }

    public String M() {
        if (this.av == null) {
            this.av = b.i(this.O);
        }
        return this.av;
    }

    public String N() {
        if (this.aw == null) {
            this.aw = b.j(this.O);
        }
        return this.aw;
    }

    public String O() {
        return b.k(this.O);
    }

    public String P() {
        if (this.ax == null) {
            this.ax = b.l(this.O);
        }
        return this.ax;
    }

    public long Q() {
        return b.m(this.O);
    }

    public boolean R() {
        if (this.G == null) {
            this.G = Boolean.valueOf(b.n(this.O));
            an.a("Is it a virtual machine? " + this.G, new Object[0]);
        }
        return this.G.booleanValue();
    }

    public boolean S() {
        if (this.H == null) {
            this.H = Boolean.valueOf(b.p(this.O));
            an.a("Does it has hook frame? " + this.H, new Object[0]);
        }
        return this.H.booleanValue();
    }

    public String T() {
        if (this.g == null) {
            this.g = AppInfo.g(this.O);
            an.a("Beacon channel " + this.g, new Object[0]);
        }
        return this.g;
    }
}
